// 自定义一个hook;
import { useState, useEffect } from 'react';
const useNetwork = () => {
    const [network, setNetworkFn] = useState(navigator.onLine);
    useEffect(() => {
        window.addEventListener('online', () => {
            setNetworkFn(true)
            //console.log('ononline');
        })
        window.onoffline = () => {
            //console.log('offline');
            setNetworkFn(false);
        }
    }, []);

    return network
}

export default useNetwork


